﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UI_StartMenu: BaseUI
{
    public InputField nameTxt;
    public Button enterGameBtn;
    public Button editNameBtn;
    public override UIConst UI_Type
    {
        get
        {
            return UIConst.UI_StartMenu;
        }
    }


    private bool isOnEditName;
    private void Awake()
    {
        enterGameBtn.onClick.AddListener(OnEnterGameBtn);
        editNameBtn.onClick.AddListener(OnEditNameBtn);
    }
    private void Start()
    {
        nameTxt.interactable = isOnEditName;

        SetUIData();
    }

    private void SetUIData()
    {
        nameTxt.text = Global.Instantce.Actor.name;
    }
    void OnEnterGameBtn()
    {
        UIManager.Instantce.Open(UIConst.UI_RoomList);
    }
    void OnEditNameBtn()
    {
        if(isOnEditName)
        {
            Global.Instantce.Actor.name = nameTxt.text;
            Global.Instantce.SaveUserData();
        }

        isOnEditName = !isOnEditName;

        nameTxt.interactable = isOnEditName;
        var editNameBtn_txt = editNameBtn.GetComponentInChildren<Text>();
        if (isOnEditName)
            editNameBtn_txt.text = "确定";
        else
            editNameBtn_txt.text = "修改";
    }
}
